

#include "string.h"

extern void stringcopy (char *_dest, const char *_src, size _sz)
{
	index i;

	for (i = 0; i < _sz; ++i)
	{
		_dest [i] = _src [i];

		if (_dest [i] == '\0')
		{
			return;
		}
	}
}


extern size stringlength (const char *_str)
{
	size i;

	for (i = 0; _str [i] != '\0'; ++i)
	{
	}

	return i;
}


extern char stringequal (const char *_a, const char *_b)
{
	index i;

	for (i = 0; _a [i] == _b [i] && _a [i] != '\0'; ++i)
	{
	}

	return _a [i] == _b [i];
}


extern char *stringfirst (char *_str, const char *_set)
{
	char *i, *j;

	for (i = _str; *i != '\0'; ++i)
	{
		for (j = _set; *j != '\0'; ++j)
		{
			if (*i == *j)
			{
				return i;
			}
		}
	}

	return NULL;
}


extern char *stringlast (char *_str, const char *_set)
{
	char *i, *j, *last = NULL;

	for (i = _str; *i != '\0'; ++i)
	{
		for (j = _set; *j != '\0'; ++j)
		{
			if (*i == *j)
			{
				last = i;
			}
		}
	}

	return last;
}


extern int sprintf (char *_dest, const char *_format, ...)
{
	/*TODO:  defnly needs to be implmeneted */

	stringcopy (_dest, "not implemented!!", 30);
}
